<?php

/**
 * Description of ArticleView
 *
 * @author Ian Clarence <ian.clarence@gmail.com>
 */
final class ArticleView extends ViewArticle {
    
    /**
     * The constructor.
     */
    public function __construct($fields = array()) {
        parent::__construct($fields);
    }
    
    /**
     * Instance of an HTML form.
     * 
     * @param array $htmlForm
     * @return mixed
     */
    protected function getHtmlFormInstance($htmlForm) {
        return $this->genHtmlFormView($this->getHtmlFormFields($htmlForm));
    }
    
    /**
     * The final rendering. 
     */
    public function make() {
        parent::make();

        /**
         * Navigation.
         */        
        switch($this->fields['panel']['article']['name']) {
            default:              
                $this->addInnerHtml(ViewHtmlElement::textInit(''));
                break;
            case 'primary_navigation':
                $this->navigationList('primaries');
                break;
            case 'welcome_page':
                $this->navigationList('ancestors');
                break;
            case 'footer_navigation':
                $this->navigationList('primaries');
                break;
            case 'left_navigation':
                $this->navigationList('children');
                $this->navigationList('siblings');
                $this->navigationList('ancestors');
                $this->navigationList('descendants');
                $this->navigationList('subdomains');
                $this->navigationList('domains');
                $this->navigationList('languages');
                break;
        }
        
        /**
         * HTML Forms. 
         */
        $htmlFormElementTypes = ViewUtils::getHtmlFormElementTypes();        
        foreach($this->fields['panel']['article']['html_forms'] as $htmlForm) {
            $viewHtmlForm = ViewHtmlForm::htmlFormInit(
                $htmlForm['form_id'], 
                $htmlForm['name'],
                'post',
                NULL,
                FALSE,
                array('session_id' => $this->fields['session_id'])
            );            
            foreach($htmlForm['html_form_elements'] as $formElementKey => $htmlFormElement) {
                
                switch($htmlFormElementTypes[$htmlFormElement['html_form_element_type']]) {
                    default:
                        break;
                    case 'checkbox':
                        break;
                    case 'input_text':
                        $viewHtmlFormElement = ViewInputText::inputTextInit(
                            $htmlFormElement['element_id'], 
                            $htmlFormElement['name'], 
                            'text',
                            isset($this->fields['request'][$htmlFormElement['name']]) ? $this->fields['request'][$htmlFormElement['name']] : NULL
                        );
                        break;
                    case 'radio':
                        break;
                    case 'select':
                        break;
                    case 'text_area':
                        break;
                }
                $viewHtmlFormElement->setLabelElement($htmlFormElement['label']);
                $viewHtmlForm->addInnerHtml($viewHtmlFormElement);
                $viewHtmlForm->addBr();
            }
            $viewHtmlForm->addButton(TRUE);
             
            $this->addInnerHtml($viewHtmlForm);
        }
        
    }

}